package com.jhs.boot.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jhs.boot.common.result.PageResult;
import com.jhs.boot.common.result.Result;
import com.jhs.boot.system.model.form.SysRfidUserForm;
import com.jhs.boot.system.model.query.SysRfidUserQuery;
import com.jhs.boot.system.model.vo.SysRfidUserVO;
import com.jhs.boot.system.service.SysRfidUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * RFID人员匹配表前端控制层
 *
 * @author zxy
 * @since 2025-10-29 16:06
 */
@Tag(name = "RFID人员匹配表接口")
@RestController
@RequestMapping("/api/v1/sys-rfid-user")
@RequiredArgsConstructor
public class SysRfidUserController  {

    private final SysRfidUserService sysRfidUserService;

    @Operation(summary = "RFID人员匹配表分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('ap:sys-rfid-user:query')")
    public PageResult<SysRfidUserVO> getSysRfidUserPage(SysRfidUserQuery queryParams ) {
        IPage<SysRfidUserVO> result = sysRfidUserService.getSysRfidUserPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增RFID人员匹配表")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('ap:sys-rfid-user:add')")
    public Result<Void> saveSysRfidUser(@RequestBody @Valid SysRfidUserForm formData ) {
        boolean result = sysRfidUserService.saveSysRfidUser(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取RFID人员匹配表表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('ap:sys-rfid-user:edit')")
    public Result<SysRfidUserForm> getSysRfidUserForm(
        @Parameter(description = "RFID人员匹配表ID") @PathVariable Long id
    ) {
        SysRfidUserForm formData = sysRfidUserService.getSysRfidUserFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改RFID人员匹配表")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('ap:sys-rfid-user:edit')")
    public Result<Void> updateSysRfidUser(
            @Parameter(description = "RFID人员匹配表ID") @PathVariable Long id,
            @RequestBody @Validated SysRfidUserForm formData
    ) {
        boolean result = sysRfidUserService.updateSysRfidUser(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除RFID人员匹配表")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('ap:sys-rfid-user:delete')")
    public Result<Void> deleteSysRfidUsers(
        @Parameter(description = "RFID人员匹配表ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = sysRfidUserService.deleteSysRfidUsers(ids);
        return Result.judge(result);
    }
}
